<template>
  <div class="box">
    <el-table :data="tableData" border style="width: 100%">
      <el-table-column
        prop="userName"
        label="姓名"
        width="120"
      ></el-table-column>
      <el-table-column
        prop="phone"
        label="手机号"
        width="120"
      ></el-table-column>
      <el-table-column fixed="right" label="操作" width="100">
        <template slot-scope="scope">
          <el-button @click="handleClick(scope.row)" type="text" size="small"
            >修改</el-button
          >
          <el-button
            type="text"
            size="small"
            @click="deleteOneSalesman(scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import api from '../../../network/apis/api';
export default {
  created() {
    this.getAllSalesmans();
  },
  methods: {
    handleClick(row) {
      this.$router.push(`/admin/updateSalesman/${row._id}`);
    },
    async deleteOneSalesman(row) {
      const data = await api.salesmans.deleteOneSalesman(row._id);
      this.getAllSalesmans();
    },
    async getAllSalesmans() {
      const { data } = await api.salesmans.getAllSalesmans();
      this.tableData = data.data;
    },
  },
  data() {
    return {
      tableData: [
        {
          userName: '',
          phone: '',
        },
      ],
    };
  },
};
</script>

<style></style>
